package collection.set;

import java.util.Objects;

public class Test5 {
    public static void main(String[] args) {
        A a1 = new A("江西刘德华");
        A a2 = new A("芜湖大司马");
        System.out.println(a1.hashCode());
        System.out.println(a2.hashCode());
    }
}

class A{
    private String name;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        A a = (A) o;
        return Objects.equals(name, a.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public A() {
    }

    public A(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return "A{name = " + name + "}";
    }
}